package com.blog.wl2023.repository;

import com.blog.wl2023.entity.ArticleComment;
import com.blog.wl2023.entity.TreasureChests;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TreasureChestsRepository extends JpaRepository<TreasureChests, Long>, JpaSpecificationExecutor<TreasureChests> {

	@Query("select new TreasureChests(t.url,t.urlName,t.imageUrl,t.typeId,t.description) from TreasureChests t where t.isDelete = 0 order by t.createTime desc")
	List<TreasureChests> getTreasureChests();

	@Modifying
	@Transactional
	@Query("update TreasureChests a set a.url=:url,a.urlName=:urlName,a.imageUrl=:imageUrl,a.description=:description  where a.uuid = :uuid")
	void updateTreasureChest(String uuid, String url, String urlName, String imageUrl, String description);

	@Query("select t from TreasureChests t where t.isDelete = 1 order by t.createTime desc")
	List<TreasureChests> manageGetTreasureChestsByIsDelete();

	@Modifying
	@Transactional
	@Query("update TreasureChests a set a.isDelete = 0 where a.uuid = :uuid")
	void passTreasureChests(String uuid);
}
